import { toMoney } from '../utils'
export default function (opt) {

    function calculateData(data) {
        let arr = []
        if (data.length) {
            arr = data.map(item => {
                if (item < 0) {
                    return -Math.log10(Math.abs(item))
                } else if (item > 0) {
                    return Math.log10(item)
                } else {
                    return 0
                }
            })
        }
        return arr
    }

    let data = opt.data ? calculateData(opt.data) : [50, 100, 110, 135, 150, 147, 260, 380, 140, 160, 155, 167];
    // console.log(opt.data);
    // console.log(data, 'data');

    let i = 0

    return {
        legend: {
            show: true,
            // top: '5%'
        },
        grid: {
            top: '10%',
            right: '5%',
            left: '7%'
        },
        tooltip: {
            trigger: 'item',
            formatter: (param) => {
                return `${param.name}月  ${toMoney(opt.data[param.dataIndex])}元`
            }
        },
        xAxis: {
            type: 'category',
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#E5E9ED',
                }
            },
            data: opt.xAxis || ['202010', '201011', '201012', '202101', '202102', '202103', '202104', '202105', '202106', '202107', '202108', '202109']
        },
        yAxis: {
            name: '金额(元)',
            type: 'value',
            // splitNumber: 5,
            splitLine: {
                show: true,
                lineStyle: {
                    color: '#E5E9ED',
                }
            },
            axisLabel:{
                formatter:(param)=>{
                    return `10^${param}`
                }
            }
        },
        series: [
            {
                name: opt.name || '在建工程',
                data: data || [50, 100, 110, 135, 150, 147, 260, 380, 140, 160, 155, 167],
                type: 'line',
                label: {
                    show: true,
                    formatter: (param) => {
                        return toMoney(opt.data[param.dataIndex])
                    }
                },
            }
        ]
    }
}